﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Data .Linq;
using System.Text;
using System.Windows.Forms;

namespace DoAn
{
    public partial class MainForm : Form
    {
        //public static MainForm mainform = new MainForm();
        private static frmDangNhap frmDangNhap = new frmDangNhap();
        private IntPtr hwmd;

        public IntPtr  Hwmd
        {
            get { return hwmd; }
            set { hwmd = value; }
        }
        public static frmDangNhap FrmDangNhap
        {
            get { return MainForm.frmDangNhap; }
            set { MainForm.frmDangNhap = value; }
        }
        
         
            
        public MainForm()
        {
            InitializeComponent();
            
            
        }

        private void đăngNhậpToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void trưởngPhòngToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }
//
        private void MainForm_Load(object sender, EventArgs e)
        {
            frmDangNhap.ShowDialog();
            hwmd = this.Handle;
            if (frmDangNhap.Taikhoan != null)
            {
                if (frmDangNhap.Taikhoan.Dangnhapok == true)
                {
                    phanquyen(frmDangNhap.Taikhoan);
                    MnuItemDangXuat.Enabled = true;
                }
            }
            
        }

        private void phanquyen(App_Code.TaiKhoan taikhoan)
        {
            if (taikhoan.Machucvu == 5)// machucvu=5,quyen la nhan vien kinh doanh
            {
              
                MnuItemNhanVien.Enabled = true;
                toolstripmnuitemNVKinhDoanh.Enabled = true;
                return ;
 
            }
            if (taikhoan.Machucvu == 6)// machucvu=6,quyen la nhan vien kho
            {
                MnuItemNhanVien.Enabled = true;
                toolstripmnuitemNVKho.Enabled = true;
                return ;

            }
            if (taikhoan.Machucvu == 1 || taikhoan.Machucvu == 2)// machucvu=1 hoac 2,quyen la giam doc hoac pho giam doc
            {
                MnuItemBanQuanLy.Enabled = true;
                return;
                

            }
            if (taikhoan.Machucvu == 3)// machucvu=3,quyen la truong phong kinh doanh
            {
                MnuItemTruongPhong.Enabled = true;
                ToolStripMenuItemkinhDoanh.Enabled = true;
                return;
            }
            if (taikhoan.Machucvu == 4)// machucvu=4,quyen la truong kho
            {
                MnuItemTruongPhong.Enabled = true;
                ToolStripMenuItemkho.Enabled = true;

            }
        
        }
        private void KhoitaoLaiMenu()
        {
            MnuItemBanQuanLy.Enabled = false;
            MnuItemTruongPhong.Enabled = false;
            ToolStripMenuItemkinhDoanh.Enabled = false;
            ToolStripMenuItemkho.Enabled = false;
            MnuItemNhanVien.Enabled = false;
            toolstripmnuitemNVKho.Enabled = false;
            toolstripmnuitemNVKinhDoanh.Enabled = false;
            MnuItemDangXuat.Enabled = false; 
        }

        private void MnuItemDangXuat_Click(object sender, EventArgs e)
        {
            frmDangNhap.Taikhoan = new DoAn.App_Code.TaiKhoan(null, null, 0, false);
            KhoitaoLaiMenu();
            MainForm_Load(sender, e);
            
        }

        private void toolstripMnuItemHoaDonBanHang_Click(object sender, EventArgs e)
        {
//hien thi form hoa don
            NhanVienKinhDoanh.frmHoaDonBanHang frmHoaDon = new DoAn.NhanVienKinhDoanh.frmHoaDonBanHang();
            frmHoaDon.ShowDialog(); 
        }

        
    }
}


